<?php

namespace App\Jobs;

use App\Libraries\Scheduler;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Libraries\Task;
use Illuminate\Support\Facades\Log;

class TaskJob2 implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable,SerializesModels;
    public $scheduler;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Scheduler &$scheduler)
    {
        //
        $this->scheduler=$scheduler;


    }
    public function getScheduler(Scheduler &$scheduler){

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
//        Log::info($this->scheduler);
        $scheduler=$this->scheduler;
        $task2 = new Task(call_user_func(function() {
            for ($i = 0; $i < 6; $i++) {
                print "task2: " . $i . "\n";
                yield;
            }
        }));
        Log::info('lalala');
        Log::info(json_encode($scheduler->getQueue()));
        $scheduler->getQueue()->enqueue($task2);

    }
}
